package com.example.boot.config;

import com.example.boot.modules.auth.jackson.OAuth2AccessTokenMixin;
import com.example.starter.jackson.module.JavaTimeModule;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.security.oauth2.common.OAuth2AccessToken;

/**
 * @author 王令
 * @since 2023/8/1 17:34
 */
@Configuration
public class WebMvcConfiguration {

    @Bean
    public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        ObjectMapper mapper = new ObjectMapper();
        JavaTimeModule javaTimeModule = new JavaTimeModule();
        mapper.registerModule(javaTimeModule);
        mapper.addMixIn(OAuth2AccessToken.class, OAuth2AccessTokenMixin.class);
        converter.setObjectMapper(mapper);
        return converter;
    }
}
